//Script file for Form 1042-S
function showHideReportingState()
{
	if (document.getElementById('reportStateTaxes').value == 'Yes')
	{
		document.getElementById('reportingStateTaxesDiv').style.display = 'block';
	}
	else
	{
		document.getElementById('reportingStateTaxesDiv').style.display = 'none';
		document.getElementById('box24').value = 0;
	}
}


function showHidewithHoldingAllowances()
{
	if (document.getElementById('withHoldingAllowances').value == 'Yes')
	{
		document.getElementById('withHoldingAllowancesDiv').style.display = 'block';
	}
	else
	{
		document.getElementById('withHoldingAllowancesDiv').style.display = 'none';
		document.getElementById('box3').value = 0;
	}
	updateBox4();
}

function updateBox4()
{
	if (document.getElementById('box3').value == "" || document.getElementById('box3').value == 0)
	{
		document.getElementById('box4').value = 0;
	}
	else
	{
		if ((document.getElementById('box2').value - document.getElementById('box3').value) > 0)
		{
			document.getElementById('box4').value = Math.round(document.getElementById('box2').value - document.getElementById('box3').value);
		}
		else
		{
			document.getElementById('box4').value = 0;
		}
	}
	updateBox7();
}

function showHideOtherWithHoldingAgentAmountDiv()
{
	if (document.getElementById('anotherWithholdingAgent').value == 'Yes')
	{
		document.getElementById('otherWithHoldingAgentAmountDiv').style.display = 'block';
	}
	else
	{
		document.getElementById('otherWithHoldingAgentAmountDiv').style.display = 'none';
		document.getElementById('box8').value = 0;
	}
	updateBox9();
}

function showHideFederalTaxesWithheldDiv()
{
	if (document.getElementById('reportingFedralTaxes').value == 'Yes')
	{
		document.getElementById('federalTaxesWithheldDiv').style.display = 'block';
		updateBox7();
	}
	else
	{
		document.getElementById('federalTaxesWithheldDiv').style.display = 'none';
		document.getElementById('box7').value = 0;
	}
	updateBox9();
}

function showHideStateTaxesWithheldDiv()
{
	if (document.getElementById('reportingStateTaxes').value == 'Yes')
	{
		document.getElementById('stateTaxesWithheldDiv').style.display = 'block';
	}
	else
	{
		document.getElementById('stateTaxesWithheldDiv').style.display = 'none';
		document.getElementById('box23').value = 0;
	}
}

function showHideOverpayOrOverwithheldDivDiv()
{
	if (document.getElementById('overpayOrOverwithheld').value == 'Yes')
	{
		document.getElementById('overpayOrOverwithheldDiv').style.display = 'block';
	}
	else
	{
		document.getElementById('overpayOrOverwithheldDiv').style.display = 'none';
		document.getElementById('box10').value = 0;
	}
}

function updateBox7()
{
	if (document.getElementById('box4').value == "" || document.getElementById('box4').value == 0)
	{
		document.getElementById('box7').value = Math.round((document.getElementById('box5').value * document.getElementById('box2').value) / 100);
	}
	else
	{
		document.getElementById('box7').value = Math.round((document.getElementById('box5').value * document.getElementById('box4').value) / 100);
	}
	updateBox9();
}

function updateBox9()
{
	document.getElementById('box9').value = Math.round(Number(document.getElementById('box7').value) + Number(document.getElementById('box8').value));
}

function roundField(fieldName)
{
	document.getElementById(fieldName).value = Math.round(document.getElementById(fieldName).value);
}


function changeAction(x)
{
	if ( x == 0 )
	{
		document.Form1042S.action ="Form1042S.php";
	}
	else
		document.Form1042S.action ="Form1042T.php";
}

function updateBox12d()
{
	document.getElementById("box12d").value = document.getElementById("city").value + " "+ ", "+ " ";
	document.getElementById("box12d").value += document.getElementById("selectedState").value + " "+ ", "+ " ";
	document.getElementById("box12d").value += document.getElementById("zip").value + " " + "," + " " + "United States";
}

function updateBox13e()
{
	document.getElementById("box13e").value = document.getElementById("foreignCity").value + " "+ ", "+ " ";
	document.getElementById("box13e").value += document.getElementById("foreignState").value  + " "+ ", "+ " ";
	document.getElementById("box13e").value += document.getElementById("foreignZip").value  + " "+ ", "+ " ";
	document.getElementById("box13e").value += document.getElementById("selectedCountry").value ;
}